package com.cat.slidingWindow;

/**
*   @description https://leetcode.cn/problems/subarray-product-less-than-k/
*   @author cat
*   @create 2025/7/31 19:49
*   @since JDK17
*/

public class Solution19 {
    public int numSubarrayProductLessThanK(int[] nums, int k) {
        int ans = 0, n = nums.length;
        long product = 1;
        for (int l = 0, r = 0; r < n; ) {
            product *= nums[r];
            if (product < k) {  // 求答案
                ans += r - l + 1;
                r++;
            } else {    //
                product /= nums[l++];
            }
        }
        return ans;
    }
}
